﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
    CodeBehind="JT_OperAdd.aspx.cs" Inherits="JTicket.UI.JT_OperAdd" %>

<%@ OutputCache Duration="1" Location="Any" NoStore="true" VaryByParam="*" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        //页面初始下载
        $(document).ready(
    function () {
        $.ajax({
            type: "get",
            url: "ThGetHandler.axd?Time=" + new Date(),
            success: function (msg) {
                var arr = eval(msg.toString());
                if (arr.length > 0) {
                    for (var i = 0; i < arr.length; i++) {
                        $("#seTheater").append("<option value=" +
                    arr[i].ThCode + ">" + arr[i].ThName + "</option>");
                    }
                }
            },
            error: function () { isAlertError(); },
            async: false
        });
        if (Flag == "Edite") {
            $("#BtnAdd").hide();

            $.ajax({
                type: "get",
                url: "LevelHandler.axd?Time=" + new Date(),
                success: function (msg) {
                    var arr = eval(msg.toString());
                    if (arr.length > 0) {
                        for (var i = 0; i < arr.length; i++) {
                            $("#seLevel").append("<option value=" +
                     arr[i].CodeVal + ">" + arr[i].CodeNote + "</option>");
                        }
                    }
                },
                error: function () { isAlertError(); },
                async: false
            });

            JTicket.UI.Service.JT_OperSvc.GetModel(ID,
        function Success(Reuslt) {
            if (Reuslt != null) {
                $("#seTheater").empty();
                $("#seTheater").append("<option  value='" + Reuslt.ThCode + "'>" + Reuslt.ThName + "</option>");
                $("#seLevel ").val(Reuslt.CurLevel);

                $("#sestate ").val(Reuslt.CurStatus);
                $("#seSaletype ").val(Reuslt.SaleType);
                $("#txtCode").val(Reuslt.OperCode);
                $("#txtName").val(Reuslt.OperName);
                $("#txtbarcode").val(Reuslt.barcode);
                Bindrol($('#seLevel').val());
                //已分配的权限
                $.ajax({
                    type: "get",
                    url: "GetRoleBussiness.axd?OperCode=" + escape(ID)+"&Time=" + new Date(),
                    success: function (msg) {
                        var arr = msg.split(',');
                        if (arr.length > 0) {
                            for (var i = 0; i < arr.length; i++) {
                                if (arr[i] != "") {
                                    var na = "#" + arr[i];
                                    $(na).attr("checked", true);
                                }
                            }
                        }
                    },
                    fail: function () { isAlertError(); },
                    async: false
                });
            } else {
                window.location.href = "JT_OperManager.aspx";
            }
        },
         function Fail(Reuslt) { isAlertError(); });

        } else {
            $.ajax({
                type: "get",
                url: "LevelHandler.axd?Time=" + new Date(),
                success: function (msg) {
                    var arr = eval(msg.toString());
                    if (arr.length > 0) {
                        for (var i = 0; i < arr.length; i++) {
                            $("#seLevel").append("<option value=" +
                     arr[i].CodeVal + ">" + arr[i].CodeNote + "</option>");
                        }
                    }
                },
                error: function () { isAlertError(); },
                async: false
            });
            Bindrol($("#seLevel").val());
            $("#BtnEdite").hide();
        }
    });
        function Add() {

            if ($('#seTheater').val() == "-1") {
                alert("请选择剧院名称"); $("#seTheater").focus(); return false;
            }
            if ($('#txtCode').val() == "") {
                alert("请输入用户编号"); $("#txtCode").focus(); return false;
            }
            if ($('#seLevel').val() == "-1") {
                alert("请选择用户等级"); $("#seLevel").focus(); return false;
            }
            if ($('#sestate').val() == "-1") {
                alert("请选择用户状态"); $("#sestate").focus(); return false;
            }
            if ($('#seSaletype').val() == "-1") {
                alert("请选择销售方式"); $("#seSaletype").focus(); return false;
            }
            var model = new JTicket.Model.OperInfo();
            model.OperCode = $("#txtCode").attr("value");
            model.OperName = $("#txtName").attr("value");
            model.barcode = $("#txtbarcode").attr("value");
            model.CurLevel = $('#seLevel').val();
            model.CurStatus = $('#sestate').val();
            model.ThCode = $('#seTheater').val();
            model.ThName = $("#seTheater").find("option:selected").text();
            model.CompanyCode = "";
            model.SaleType = $('#seSaletype').val();
            model.Roles = CheckValue();
            $("#BtnAdd").attr("disabled", "disabled");
            JTicket.UI.Service.JT_OperSvc.Add(model,
            function Success(Result) {
                alert(Result);
                $("#BtnAdd").removeAttr("disabled");
                window.location.href = "JT_OperManager.aspx";
            }, function fail(Result) { isAlertError(); });
        }
        function Update() {
            if ($('#seTheater').val() == "-1") {
                alert("请选择剧院名称"); $("#seTheater").focus(); return false;
            }
            if ($('#txtCode').val() == "") {
                alert("请输入用户编号"); $("#txtCode").focus(); return false;
            }
            if ($('#seLevel').val() == "-1") {
                alert("请选择用户等级"); $("#seLevel").focus(); return false;
            }
            if ($('#sestate').val() == "-1") {
                alert("请选择用户状态"); $("#sestate").focus(); return false;
            }
            if ($('#seSaletype').val() == "-1") {
                alert("请选择销售方式"); $("#seSaletype").focus(); return false;
            }

            var model = new JTicket.Model.OperInfo();
            model.OperCode = $("#txtCode").attr("value");
            model.OperName = $("#txtName").attr("value");
            model.barcode = $("#txtbarcode").attr("value");
            model.CurLevel = $('#seLevel').val();
            model.CurStatus = $('#sestate').val();
            model.ThCode = $('#seTheater').val();
            model.ThName = $("#seTheater").find("option:selected").text();
            model.CompanyCode = "";
            model.SaleType = $('#seSaletype').val();
            model.Roles = CheckValue();
            JTicket.UI.Service.JT_OperSvc.Update(model,
            function Success(Result) { alert("修改成功！"); },
            function fail(Result) { isAlertError(); });
        }
        function Bindrol(Val) {
            var str;
            $("#rolList").html("数据正在加载...");
            $.ajax({
                type: "get",
                url: "RoleHandler.axd?Val=" + Val + "&Time=" + new Date(),
                success: function (msg) {
                    $("#rolList").html("");
                    var arr = eval(msg.toString());
                    if (arr.length > 0) {
                        for (var i = 0; i < arr.length; i++) {
                            $("#rolList").append("<div style=\"width:150px;float:left\"><input name=cb type=\"checkbox\" value=\"" + arr[i].CodeVal + "\" id=\"" + arr[i].CodeVal + "\" class=\"checkbox\"  />" + arr[i].CodeNote + "&nbsp;&nbsp;</div>");
                        }
                    }
                },
                error: function () { $("#rolList").html("数据加载错误."); },
                async: false
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ScriptManager ID="sm" runat="server">
        <Services>
            <asp:ServiceReference InlineScript="true" Path="~/Service/JT_OperSvc.asmx" />
        </Services>
    </asp:ScriptManager>
    <table align="center" border="0" cellpadding="4" cellspacing="1" class="toptable grid"
        width="100%">
        <tr>
            <td class="category t2" height="25" width="100">
                用户添加
            </td>
            <td class="category" height="25">
            </td>
        </tr>
    </table>
    <table cellpadding="1" cellspacing="1" id="TbInfo" class="TbInfo">
        <tr>
            <td align="right" bgcolor="#3890B5" class="B" style="width: 130px">
                名称
            </td>
            <td height="25" align="right" bgcolor="#3890B5" class="B">
                操作
            </td>
            <td align="right" bgcolor="#3890B5" class="B" style="width: 50px">
                说明
            </td>
        </tr>
        <tr>
            <td align="center" bgcolor="#F6F6F6" style="width: 130px; height: 25px;">
                所属剧院：
            </td>
            <td align="left" bgcolor="#F6F6F6" style="height: 25px">
                <select id="seTheater" name="S2">
                    <option value="-1">--请选择剧院名称--</option>
                </select>
            </td>
            <td bgcolor="#F6F6F6" style="height: 25px; width: 171px;">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td align="center" bgcolor="#F6F6F6" style="width: 130px; height: 25px;">
                编用户号：
            </td>
            <td align="left" bgcolor="#F6F6F6" style="height: 25px">
                <input id="txtCode" type="text" />
            </td>
            <td bgcolor="#F6F6F6" style="height: 25px; width: 171px;">
                必填
            </td>
        </tr>
        <tr>
            <td align="center" bgcolor="#F6F6F6" style="width: 130px; height: 25px;">
                用户名称：
            </td>
            <td align="left" bgcolor="#F6F6F6" style="height: 25px">
                <input id="txtName" type="text" style="width: 300px;" />
            </td>
            <td bgcolor="#F6F6F6" style="height: 25px; width: 171px;">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td align="center" bgcolor="#F6F6F6" style="width: 130px; height: 25px;">
                用户等级：
            </td>
            <td align="left" bgcolor="#F6F6F6" style="height: 25px">
                <select id="seLevel" name="S3" onchange="Bindrol($('#seLevel').val());">
                    <option value="-1">--请选择用户等级--</option>
                </select>
            </td>
            <td bgcolor="#F6F6F6" style="height: 25px; width: 171px;">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td align="center" bgcolor="#F6F6F6" style="width: 130px; height: 25px;">
                用户状态：
            </td>
            <td align="left" bgcolor="#F6F6F6" style="height: 25px">
                <select id="sestate" name="S4">
                    <option value="-1">--请选择用户状态--</option>
                    <option value="0">正常</option>
                    <option value="1">休假</option>
                    <option value="2">离职</option>
                </select>
            </td>
            <td bgcolor="#F6F6F6" style="height: 25px; width: 171px;">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td align="center" bgcolor="#F6F6F6" style="width: 130px; height: 25px;">
                折扣方式：
            </td>
            <td align="left" bgcolor="#F6F6F6" style="height: 25px">
                <select id="seSaletype" name="S5">
                    <option value="-1">--请选择销售方式--</option>
                    <option value="1001">不可自由打折</option>
                    <option value="1002">可自由打折</option>
                    <option value="1003">按指定分配折扣率</option>
                </select>
            </td>
            <td bgcolor="#F6F6F6" style="height: 25px; width: 171px;">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td align="center" bgcolor="#F6F6F6" style="width: 130px; height: 25px;">
                员工条码：
            </td>
            <td align="left" bgcolor="#F6F6F6" style="height: 25px">
                <input id="txtbarcode" type="text" />
            </td>
            <td bgcolor="#F6F6F6" style="height: 25px; width: 171px;">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td align="center" bgcolor="#F6F6F6" style="width: 130px; height: 25px;">
                权限列表：
            </td>
            <td align="left" bgcolor="#F6F6F6" style="height: 25px">
                <p id="rolList">
                </p>
            </td>
            <td bgcolor="#F6F6F6" style="height: 25px; width: 171px;">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td align="center" bgcolor="#F6F6F6" style="width: 130px">
            </td>
            <td height="25" bgcolor="#F6F6F6" align="center">
                <input type="button" id="BtnAdd" value="创  建" onclick="Add();" onmousemove="showBtnOver(this)"
                    onmouseout="showBtnOut(this)" class="submitMiniGreen" />
                <input type="button" id="BtnEdite" value="保  存" onclick="Update();" onmousemove="showBtnOver(this)"
                    onmouseout="showBtnOut(this)" class="submitMiniGreen" />
                <input type="button" id="BtnBack" value="返  回" onclick="javascript:window.location.href ='JT_OperManager.aspx'"
                    onmousemove="showBtnOver(this)" onmouseout="showBtnOut(this)" class="submitMiniGreen" />
            </td>
            <td bgcolor="#F6F6F6" style="width: 171px">
                &nbsp;
            </td>
        </tr>
    </table>
</asp:Content>
